// 编辑危大工程

<template>
    <f7-page class="add">
        <f7-navbar>
            <f7-nav-left>
                <f7-link back
                         icon-material="arrow_back"></f7-link>
            </f7-nav-left>
            <f7-nav-title>危大工程</f7-nav-title>
            <f7-nav-right>
                <f7-icon f7="house"
                         @click.native="fnToHome()"></f7-icon>
            </f7-nav-right>
        </f7-navbar>

        <van-notice-bar background="#fff"
                        color="#345">
            <f7-icon solt="left-icon"
                     color="#3385ff"
                     f7="layers_alt_fill"></f7-icon>
            <span>{{models.engineeInfo.engineeName}}</span>
        </van-notice-bar>

        <van-form input-align="right"
                  disabled
                  ref="form">
            <van-field name="radio"
                       required
                       label="类型">
                <van-radio-group slot="input"
                                 disabled
                                 v-model="models.model.isDanger"
                                 direction="horizontal">
                    <van-radio :name="1">危大工程</van-radio>
                    <van-radio :name="2">超危大工程</van-radio>
                </van-radio-group>
            </van-field>

            <van-field v-model="models.model.module"
                       label="名称"
                       required
                       disabled
                       :rules="[{'required': true}]"
                       placeholder="请输入">
            </van-field>

            <van-field v-model="models.model.riskTypeName"
                       readonly
                       required
                       disabled
                       label="类别">
                <div slot="input">
                    <v-picker-div placeholder="请选择"
                                  disabled
                                  :is-link="false"
                                  :columns="controlData.riskTypeEnums"
                                  :assignment="models.model"
                                  code="riskTypeCode"
                                  name="riskTypeName"
                                  :rules="[{'required': true}]"
                                  @confirm="emitRiskType">
                    </v-picker-div>
                </div>
            </van-field>

            <v-dynamic-forms :valueList="models.valueList"
                             :typeList="typeList"
                             :riskListId="models.model.riskListId"
                             disabled
                             :confList="confList">
            </v-dynamic-forms>

            <!-- 编辑的部分 -->
            <van-form input-align="right">
                <van-field v-model="models.model.riskStatusName"
                           readonly
                           required
                           label="施工状态"
                           placeholder="请选择">
                    <div slot="input">
                        <v-picker-div placeholder="请选择"
                                      :columns="controlData.riskStatusEnums"
                                      :assignment="models.model"
                                      :rules="[{'required': true}]"
                                      code="riskStatus"
                                      name="riskStatusName">
                        </v-picker-div>
                    </div>
                </van-field>

                <van-field readonly
                           clickable
                           :value="models.model.startDate"
                           label="计划开工日期"
                           placeholder="请选择"
                           right-icon="tosend"
                           required
                           :rules="[{'required': true}]"
                           @click="calendarShow1 = true">
                </van-field>
                <van-calendar v-model="calendarShow1"
                              color="#3385ff"
                              get-container="body"
                              @confirm="onConfirm3">
                </van-calendar>

                <van-field readonly
                           clickable
                           :value="models.model.endDate"
                           label="计划完工日期"
                           placeholder="请选择"
                           right-icon="tosend"
                           required
                           :rules="[{'required': true}]"
                           @click="calendarShow2 = true">
                </van-field>
                <van-calendar v-model="calendarShow2"
                              color="#3385ff"
                              get-container="body"
                              @confirm="onConfirm4">
                </van-calendar>
            </van-form>
            <!-- 编辑的部分 end -->

            <van-field label="施工方案"
                       class="file-field"
                       required
                       input-align="left">
                <f7-picture-upload slot="input"
                                   ref="plan"
                                   disabled
                                   uploadId="riskList_plan"
                                   :params="{type:'attach', dataKey: models.model.riskListId, bizType: 'riskList_plan'}">
                </f7-picture-upload>
            </van-field>

            <van-field v-show="models.model.isDanger == 2"
                       label="论证报告"
                       class="file-field"
                       required
                       input-align="left">
                <f7-picture-upload slot="input"
                                   ref="report"
                                   disabled
                                   uploadId="riskList_report"
                                   :params="{type:'attach', dataKey: models.model.riskListId, bizType: 'riskList_report'}">
                </f7-picture-upload>
            </van-field>
        </van-form>

        <f7-toolbar position="bottom"
                    no-shadow
                    v-has="'risk:riskList:save'"
                    class="fff">
            <f7-button fill
                       class="submit-btn"
                       @click="fnSubmit()">提交</f7-button>
        </f7-toolbar>
    </f7-page>
</template>

<script>
import controller from "@/libs/framework/workflowController"
import vDynamicForms from "./components/v-dynamic-forms/index.vue"

export default class instance extends controller {
    onBeforeInit () {
        this.urls = {
            model: '/risk/riskList/initRiskList'
        }
    }
    mixin () {
        return {
            components: {
                vDynamicForms
            },
            data () {
                return {
                    models: {
                        // 危大工程信息
                        model: {},
                        // 基坑等动态信息
                        valueList: [],
                        // 项目信息
                        engineeInfo: {}
                    },
                    controlData: {

                    },
                    typeList: [],
                    confList: [],
                    selectUser: {
                        selectComment: null,
                        comment: null,
                        comments: [],
                        tran: [],
                        activity: "",
                        users: [],
                    },

                    calendarShow1: false,
                    calendarShow2: false
                }
            },
            methods: {
                onConfirm3 (date) {
                    this.models.model.startDate = this.$formatter.formatStartDateTime(date)
                    this.calendarShow1 = false
                },
                onConfirm4 (date) {
                    this.models.model.endDate = this.$formatter.formatStartDateTime(date)
                    this.calendarShow2 = false
                },
                // 提交
                fnSubmit () {
                    let form = {
                        riskListId: this.models.model.riskListId,
                        riskStatus: this.models.model.riskStatus,
                        riskStatusName: this.models.model.riskStatusName,
                        startDate: this.models.model.startDate,
                        endDate: this.models.model.endDate,
                    }

                    this.$util.request('/risk/riskList/updateRisk', form, 'post').then(res => {
                        if (res.status == 200 && res.data.success) {
                            this.$toast("提交成功")
                        } else {
                            this.$toast("提交失败")
                        }
                    })
                },
                // 类型选择
                emitRiskType ({ data }) {
                    this.$util.request('/risk/riskList/getFormList', {
                        riskType: data.code
                    }, 'post').then(res => {
                        if (res.status == 200) {
                            this.confList = res.data.confList
                            this.typeList = res.data.typeList
                        }
                    })
                }
            }
        }
    }
}
</script>

<style lang="less" scoped>
@deep: ~">>>";

.add {
    .submit-btn {
        flex: 1;
        margin: 0 10px;
    }

    .file-field {
        flex-direction: column;
    }

    @{deep}.v-picker-div {
        padding: 0;
    }
}
</style>
